package com.arquitectonic.server.persistencia;

import java.util.Properties;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManagerFactory;

public final class PMF {

	private PersistenceManagerFactory pmfInstance;

	private PMF() {

		Properties propiedadesSQL = new Properties();

		propiedadesSQL.setProperty("javax.jdo.PersistenceManagerFactoryClass",
				"org.datanucleus.api.jdo.JDOPersistenceManagerFactory");
		propiedadesSQL.setProperty("javax.jdo.option.ConnectionDriverName",
				"com.mysql.jdbc.Driver");
		propiedadesSQL.setProperty("javax.jdo.option.ConnectionURL",
				"jdbc:mysql://localhost:3306/nucleus");
		propiedadesSQL.setProperty("javax.jdo.option.ConnectionUserName", "root");
		propiedadesSQL.setProperty("javax.jdo.option.ConnectionPassword", "");
		propiedadesSQL.setProperty("datanucleus.autoCreateTables", "true");

		
		this.pmfInstance = JDOHelper.getPersistenceManagerFactory(propiedadesSQL);

		
//		this.pmfInstance = JDOHelper
//		  .getPersistenceManagerFactory("transactions-optional");
		 

	}

	public PersistenceManagerFactory get() {
		return pmfInstance;
	}

	private static PMF INSTANCE = null;

	private synchronized static void createInstance() {
		if (INSTANCE == null) {
			INSTANCE = new PMF();
		}
	}

	public static PMF getInstance() {
		if (INSTANCE == null)
			createInstance();
		return INSTANCE;
	}

}
